<?php

include APPPATH.'controllers/gnc_mng.php';

class Apl extends Gnc_mng {

	function index()
	{
		$prefix = get_application($this);
		$application = $prefix;		

		$groups = $this->model->get_data_from_query(array('nkey', 'description'), NULL, NULL, NULL, NULL, NULL, 'sys_r_unit_group');
			
		$units = $this->model->get_data_from_query(array('nkey', 'key_sys_unit_group', 'key_sys_application', 'description'), array('key_sys_application' => $application), NULL, NULL, NULL, NULL, 'sys_d_unit');
			
		$units_by_group = $groups;
		

		foreach($groups as $idx => $value) {
			foreach($units as $_idx => $_value) {
				//print_r_pre( $_value['key_sys_unit_group']);
				if (strcasecmp($value['nkey'], $_value['key_sys_unit_group']) == 0) {
					$unit = $units[$_idx];
					$unit['application'] = $unit['key_sys_application'];
					unset($unit['key_sys_unit_group']);
					$units_by_group[$idx]['units'][] = $unit;
				}
			}
		}
		//echo ("oke");
		//print_r_pre($units_by_group);

		$data = array(
			'application' => $prefix,
			'application_title' => $this->common->get_application_description($prefix),
			'page' => 'Main',
			'navigation' => $this->load->view('nav/default', '', true),
			'content' => $this->load->view('apl/viewer/main', array('units_by_group' => $units_by_group), true),
		);	// data yang akan dipassing ke view
		$this->load->view('layout/default', $data);
	}
}
